package com.black.web.controller.exercise;

import com.black.app.domain.exercise.AppExerciseGroup;
import com.black.app.domain.req.exercise.add.AppExerciseGroupAddReq;
import com.black.app.domain.req.exercise.edit.AppExerciseGroupEditReq;
import com.black.app.service.exercise.AppExerciseGroupService;
import com.black.common.annotation.Log;
import com.black.common.core.controller.BaseController;
import com.black.common.core.domain.R;
import com.black.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags = "后台-锻炼动作组相关Api")
@RestController
@RequestMapping("/admin/exercise/group")
public class AdminExerciseGroupController extends BaseController {

    @Autowired
    private AppExerciseGroupService exerciseGroupService;

    @Log(title = "添加动作组", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('exercise:group:add')")
    @ApiOperation(value = "添加动作组")
    @PostMapping
    public R add(@RequestBody @Valid AppExerciseGroupAddReq req) {
        return isSuccess(exerciseGroupService.add(req));
    }

    @Log(title = "修改动作组", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('exercise:group:edit')")
    @ApiOperation(value = "修改动作组")
    @PutMapping
    public R edit(@RequestBody @Valid AppExerciseGroupEditReq req) {
        return isSuccess(exerciseGroupService.edit(req));
    }

    /**
     * 根据id查询动作组
     */
    @PreAuthorize("@ss.hasPermi('exercise:group:query')")
    @ApiOperation(value = "根据id查询动作组")
    @GetMapping("/{groupId}")
    public R<AppExerciseGroup> findById(@PathVariable Long groupId) {
        AppExerciseGroup group = exerciseGroupService.findById(groupId);
        return R.ok(group);
    }

    @Log(title = "删除动作组", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('exercise:group:remove')")
    @ApiOperation(value = "删除动作组")
    @DeleteMapping("/{groupId}")
    public R delete(@PathVariable Long groupId) {
        return isSuccess(exerciseGroupService.deleteById(groupId));
    }


}
